package com.zx.controller;/*
 *@program:SSM
 *@author: zhangjian
 *@Time: 2021/7/22  22:49
 */


import com.zx.entity.Change;
import com.zx.entity.Project;
import com.zx.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;

import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller
public class ProjectController {

    @Autowired
    private ProjectService projectService;

    /**
    添加申请信息
     */
    @RequestMapping("/addproject")
    public String addProject(Project project){
        projectService.addProject(project);
        return "redirect:index1.jsp";

    }

    @InitBinder
    public void initData(WebDataBinder wdb){
        wdb.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
    }



    //申请验收的项目
    @ResponseBody
    @RequestMapping("/findMyProject")
    public List  findMyProject(HttpSession session){
       String user = String.valueOf(session.getAttribute("user"));
      return projectService.findMyProject(user,"待评审");
    }
    @ResponseBody
    @RequestMapping("/findProjectByID2")
    public Object  findProjectByID2(String pid){
        return projectService.findProjectByID2(pid);
    }
    @ResponseBody
    @RequestMapping("/findcontractByPid")
    public Object  findcontractByPid(String pid){
        return projectService.findcontractByPid(pid);
    }
    @ResponseBody
    @RequestMapping("/findFundsByPID")
    public Object  findFundsByPID(String pid){
        return projectService.findFundsByPID(pid);
    }
    @RequestMapping("/checkProject")
    public void checkProject(String pid){
        projectService.checkProject(pid);
    }
    @ResponseBody
    @RequestMapping("/findAllProject2")
    public List findAllProject2(){
        return  projectService.findAllProject2();
    }
    @RequestMapping("/toCheck")
    public void toCheck(String pid){
        projectService.toCheck(pid);
    }
    @ResponseBody
    @RequestMapping("/findallproject3")
    public List findallproject3(String page){
        return projectService.findallproject3(page);
    }
    @ResponseBody
    @RequestMapping("/getPPages")
    public int getPPages(){
        return projectService.getPPages();
    }
    @RequestMapping("/changeproject")
    public void changeproject(Change change){
        projectService.changeproject(change);
    }
    @RequestMapping("/approveChange")
    public void approveChange(String pid,String pone,String pmsg,String chpeople){
        projectService.updateChange(pid,pone,pmsg,chpeople);
    }
   @RequestMapping("/deletechange")
    public void deletechange(String pid){
        projectService.deletechange(pid);
   }
   @ResponseBody
   @RequestMapping("/findAllchange")
    public List findAllchange(){
      return projectService.findAllchange();
   }



    /**
     * 添加意见栏（受理）
     */
    @RequestMapping("/updateAdvice")
    public String updateAdvice(Project project){
        projectService.updateAdvice(project);
        return "redirect:index.jsp";
    }



    /**
     * 添加意见栏（评审）
     */
    @RequestMapping("/updateAdvice1")
    public String updateAdvice1(Project project){
        projectService.updateAdvice1(project);
        return "redirect:index.jsp";
    }

    /**
     * 添加意见栏（立项）
     */
    @RequestMapping("/updateAdvice2")
    public String updateAdvice2(Project project){
        projectService.updateAdvice2(project);
        return "redirect:index.jsp";
    }


    /**
     * 查询受理信息
     */
    @ResponseBody
    @RequestMapping("/findProjectShou")
    public List findProjectShou(){
        List<Project> list = projectService.findProjectShou();
        return list;
    }

    /**
     * 查询评审信息
     */
    @ResponseBody
    @RequestMapping("/findProjectPing")
    public List findProjectPing(){
        List<Project> list = projectService.findProjectPing();
        return list;
    }


    /**
     * 查询立项信息
     */
    @ResponseBody
    @RequestMapping("/findProjectLi")
    public List findProjectLi(){
        List<Project> list = projectService.findProjectLi();
        return list;
    }

    /**
     * 删除申请信息
     */
    @RequestMapping(value = "/deleteproject",method = RequestMethod.POST)
    @ResponseBody
    public String deleteProject(Integer pid){
        projectService.deleteProject(pid);
        return "redirect:index.jsp";
    }

    /**
     * 更改申请信息
     */
    @RequestMapping("/updateproject")
    public String updateProject(Project project){
        projectService.updateProject(project);
        return "redirect:index.jsp";
    }

    /**
     * 查询申请信息
     */
    @ResponseBody
    @RequestMapping("/findAll")
    public List findAll(){
        List<Project> list = projectService.findAll();
        return list;
    }

    /**
     * 查询全部
     */
    @ResponseBody
    @RequestMapping("/findProjectShen")
    public List findProjectShen(){
        List<Project> list = projectService.findProjectShen();
        return list;
    }



    /**
     * 更新信息前查询
     */
    @RequestMapping("/findProjectByID")
    public ModelAndView findProjectByID(int pid) {
        Project project = projectService.findProjectByID(pid);
        ModelAndView mv = new ModelAndView();
        mv.addObject("project",project);
        mv.setViewName("project-update");
        return mv;
    }

    /**
     * 更新
     */
    @RequestMapping("/updateProjectByID")
    public String updateProjectByID(Project project){
        projectService.updateProjectByID(project);
        return "redirect:index.jsp";
    }
}

